package com.example.demo.service;

import com.example.demo.entity.CultureBackgroundCollection;
import com.example.demo.mapper.CultureBackgroundCollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CultureBackgroundCollectionImpl implements CultureBackgroundCollectionService{

    @Autowired
    private CultureBackgroundCollectionMapper cultureBackgroundCollectionMapper;

    // 添加收藏
    @Override
    public boolean addCollection(CultureBackgroundCollection cultureBackgroundCollection) {
        return cultureBackgroundCollectionMapper.addCollection(cultureBackgroundCollection) > 0;
    }

    // 删除收藏（修改后接收 CultureBackgroundCollection 对象）
    @Override
    public boolean deleteCollection(CultureBackgroundCollection cultureBackgroundCollection) {
        return cultureBackgroundCollectionMapper.deleteCollection(
                cultureBackgroundCollection.getUser_id(), cultureBackgroundCollection.getCulture_background_detail_id()) > 0;
    }

    // 获取用户的收藏列表
    @Override
    public List<CultureBackgroundCollection> getCollectionsByUserId(Integer userId) {
        return cultureBackgroundCollectionMapper.getCollectionsByUserId(userId);
    }

    // 检查是否收藏
    @Override
    public boolean isCollected(Integer userId, Integer cultureBackgroundDetailId) {
        return cultureBackgroundCollectionMapper.checkIfCollected(userId, cultureBackgroundDetailId) > 0;
    }
}
